# Contributor: Ty Sarna <ty@sarna.org>
# Maintainer: Ty Sarna <ty@sarna.org>
pkgname=docker-credential-ecr-login
pkgver=0.4.0
pkgrel=0
pkgdesc="Credential helper for Docker to use the AWS Elastic Container Registry"
url="https://github.com/awslabs/amazon-ecr-credential-helper"
arch="x86_64 aarch64"
license="Apache-2.0"
depends="docker"
makedepends="go docker"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://amazon-ecr-credential-helper-releases.s3.us-east-2.amazonaws.com/$pkgver/release.tar.gz"
builddir="$srcdir/src/github.com/awslabs/amazon-ecr-credential-helper/ecr-login"

prepare() {
	default_prepare
	mkdir -p "$srcdir/src/github.com/awslabs/amazon-ecr-credential-helper"
	mv "$srcdir"/ecr-login "$builddir"/
}

build() {
	GOPATH="$srcdir" go build -v -o bin/$pkgname \
		-ldflags "-s -X github.com/awslabs/amazon-ecr-credential-helper/ecr-login/version.Version=$pkgver" \
		$builddir/cli/docker-credential-ecr-login
}

check() {
	GOPATH="$srcdir" go test -v -timeout 30s -short
}

package() {
	install -m750 -o root -g docker \
		-D bin/$pkgname \
		"$pkgdir"/usr/bin/$pkgname
	install -Dm644 $srcdir/docs/$pkgname.1 \
		"$pkgdir"/usr/share/man/man1/$pkgname.1
}

sha512sums="ce8b8b9be77da2eccc4098b11f206521d6d9b3aac3ee2ed7c616a099a03e0819716bc2d1cb5b2028f5844b877c77af90dab1bed26102ce52e0be51d4113b050c  docker-credential-ecr-login-0.4.0.tar.gz"
